<template>
	<view class="content">
		<text style="font-size: 36rpx; font-weight: bold;">子组件B</text>
		<view class="b-box" style="margin-top: 20rpx; margin-left: 30rpx;">
			<text>CompA组件传进来的值:</text>
			<text class="intent-text-box"
				style="font-weight: bold; color: blue; margin-left: 10rpx;">{{ result }}</text>
		</view>
		<view class="b-box" style="margin: 30rpx 30rpx; display: flex; align-items: center;">
			<text>回传值:</text>
			<input type="text" v-model="callbackValue"
				style="color: blue; border: 1px solid #eee; padding: 10rpx; margin-left: 20rpx; flex: 1;"
				placeholder="请输入回传值" />
			<button @click="sendOutside()" size="mini"
				style="margin-left: 20rpx; background-color: blue; color: white; border: none;">
				回传
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				callbackValue: '',
				result: ''
			}
		},
		created() {
			uni.$on('getIntent', (msg) => {
				this.result = msg;
			});
		},
		methods: {
			sendOutside() {
				this.$emit('callBackFun', this.callbackValue);
			}
		},
		onUnload() {
			uni.$off('getIntent');
		}
	}
</script>

<style scoped>
	.content {
		background-color: #f8f8f8;
		padding: 20rpx;
		border-radius: 10rpx;
		margin: 0 30rpx;
	}
</style>